package com.ctshk.rpc.goods.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ctshk.rpc.goods.dto.ShoppingShopDTO;
import com.ctshk.rpc.goods.entity.ShoppingShop;
import com.ctshk.rpc.goods.mapper.provider.ShoppingShopProvider;
import com.ctshk.rpc.goods.req.ShoppingShopPageReq;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 商城管理 Mapper 接口
 * </p>
 *
 * @author 姜斌文
 * @since 2021-04-06
 */
public interface ShoppingShopMapper extends BaseMapper<ShoppingShop> {

    /**
     * 根据shopId查询
     * @param id id
     * @param status 狀態
     * @return List<ShoppingShopKeyWord>
     */
    @Update("update t_shopping_shop set STATUS = #{status} WHERE id = #{id}")
    void updateShoppingShopStatus(@Param("id") long id, @Param("status") Integer status);
    
    @SelectProvider(type = ShoppingShopProvider.class, method = "findShoppingShopByAll")
    IPage<ShoppingShopDTO> findShoppingShopByAll(IPage<ShoppingShopDTO> page, ShoppingShopPageReq pageReq);

    @Select("<script>" +
            "SELECT " +
            "   t.id,t.shop_name " +
            "FROM " +
            "   t_shopping_shop t " +
            "WHERE " +
            "   t.status = 1 AND t.is_deleted = 0 " +
            "   <if test='userIds != null'>AND t.create_id in (${userIds})</if> " +
            "</script>")
	List<ShoppingShopDTO> findShoppingShopNameList(@Param("userIds") String userIds);

    @Select("SELECT t.id, t.shop_name, t.shop_describe, t.shop_logo, t.shop_default_picture, t.customer_service_hotline, t.ccustomer_service_email, t.is_distribution_allowed, t.Is_it_self_provided, t.share_title, t.share_pictures, t.payment_overtime, t.receivin_goods_overtime, t.order_overtime, t.is_distribution_allowed, t.Is_it_self_provided FROM t_shopping_shop t WHERE t.status = 1 AND t.is_deleted = 0 AND t.id = #{id}")
    ShoppingShopDTO findShoppingShopInfoById(@Param("id") Long id);

}
